/** 权限指令**/
import Vue from 'vue'
import xss from 'xss'
Vue.directive('has', {
    inserted: function (el, binding, vnode) {
        // 获取按钮权限
        const promiseBtns = vnode.context.$route.meta.promiseBtns || []
        const { value } = binding
        let valueArr = value.split(':')
        if (!promiseBtns[valueArr[0]]) {
            el.remove()
        } else {
            if (!valueArr[1]) {
                el.innerHTML = xss(el.innerHTML + `<span>${promiseBtns[valueArr[0]]}</span>`, {
                    onIgnoreTag: function (tag, html, options) {
                        if (tag === 'svg' || tag === 'path') {
                            return html
                        }
                    },
                    onIgnoreTagAttr: function (tag, name, value, isWhiteAttr) {
                        return name + '="' + value + '"'
                    },
                })
                el.style.width = 'max-content'
            }
        }
    },
})
Vue.directive('has-access', {
    inserted: function (el, binding, vnode) {
        // 获取按钮权限
        const promiseBtns = vnode.context.$route.meta.promiseBtns || []
        const { value } = binding
        let valueArr = value.split(':')
        if (!promiseBtns[valueArr[0]]) {
            el.remove()
        }
    },
})
